package com.bckj.fastboot.iot.biz.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.bckj.fastboot.security.model.AuthUser;
import com.bckj.fastboot.security.util.SecurityUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        Long userId = SecurityUtils.getUser().map(AuthUser::getId).orElse(0L);
        this.strictInsertFill(metaObject, "createId", Long.class, userId);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        Long userId = SecurityUtils.getUser().map(AuthUser::getId).orElse(0L);
        this.strictInsertFill(metaObject, "updateId", Long.class, userId);
    }

}